package com.baseframe.common.service;

import com.baseframe.common.constant.BaseLauncherConstant;
import com.baseframe.launch.scan.ImportLauncher;
import com.baseframe.launch.service.BaseLauncherService;
import com.baseframe.launch.utils.PropsUtil;
import org.springframework.boot.builder.SpringApplicationBuilder;

import java.util.Properties;


@ImportLauncher
public class BaseLauncherServiceImpl implements BaseLauncherService {
    @Override
    public void launcher(SpringApplicationBuilder builder, String appName, String profile, boolean isLocalDev) {
        Properties props = System.getProperties();
        // 通用注册
        PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.server-addr", BaseLauncherConstant.getNacosAddr(profile));
        PropsUtil.setProperty(props, "spring.cloud.nacos.config.server-addr", BaseLauncherConstant.getNacosAddr(profile));

        //配置nacos配置中心和注册中心
        System.out.println("spring.cloud.nacos.discovery.server-addr: " + BaseLauncherConstant.getNacosAddr(profile));
        System.out.println("spring.cloud.nacos.config.server-addr: " + BaseLauncherConstant.getNacosAddr(profile));

        //是否开启多数据源
        PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "false");

        //sentinel相关配置
//        PropsUtil.setProperty(props, "spring.cloud.sentinel.transport.dashboard", LauncherConstant.getNacosAddr(profile));
//        System.out.println("spring.cloud.nacos.sentinel.transport.dashboard: " + LauncherConstant.getNacosAddr(profile));
//        System.out.println("spring.cloud.nacos.sentinel.transport.dashboard: " + profile);





    }
}
